package com.loper7.base.utils;

/**
 * Created by Administrator on 2016/10/14.
 */

import android.content.Context;
import android.os.CountDownTimer;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.loper7.base.R;


/**
 * Created by Jackie on 2015/11/30.
 */
public class VerifyCodeTimerUtils extends CountDownTimer {
    private TextView mTextView;
    private Context context;
    private VerifyCodeTimerUtils verifyCodeTimerUtils;

    /**
     * @param textView          The TextView
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receiver
     *                          {@link #onTick(long)} callbacks.
     */
    public VerifyCodeTimerUtils(Context context, TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.context = context;
        this.mTextView = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false); //设置不可点击
        long time = (millisUntilFinished + 100) / 1000 >= 1 ? (millisUntilFinished + 100) / 1000 : 1;
        mTextView.setText(time + "秒");  //设置倒计时时间
        mTextView.setTextColor(ContextCompat.getColor(context, R.color.colorTextGray));
    }

    @Override
    public void onFinish() {
        mTextView.setText("重新获取");
        mTextView.setClickable(true);//重新获得点击
        mTextView.setTextColor(ContextCompat.getColor(context, R.color.colorTextBlack));
    }
}